package com.bounds.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.bounds.dao.HospitalDao;
import com.bounds.dao.ItemDao;
import com.bounds.dao.PersonDao;
import com.bounds.dao.ProductDao;
import com.bounds.entity.Hospital;
import com.bounds.entity.Item;
import com.bounds.entity.Pager;
import com.bounds.entity.Person;
import com.bounds.entity.Product;

@SuppressWarnings("serial")
public class ItemAction extends BaseAction{
	@Autowired
	private ItemDao itemDao;
	@Autowired
	private HospitalDao hospitalDao;
	@Autowired
	private PersonDao personDao;
	@Autowired
	private ProductDao productDao;
	private List<Hospital> hospitals;
	private List<Person> persons;
	private List<Product> products;
	private List<Item> items;
	private Pager<Item> page;
	private Item item;
	
	public String list(){
		items = itemDao.qryItems(item);
		return "list";
	}
	
	public String listForPage(){
		page = this.itemDao.qryItemsForPage(item, getPageNo(), getPageSize());
		return "page";
	}
	
	public String save(){
		if(item.getId()==null)
			this.itemDao.addItem(item);
		else
			this.itemDao.updateItem(item);
		return "goBack";
	}
	
	public String delete(){
		this.itemDao.delItem(item.getId());
		return "goBack";
	}
	
	public String gotoEdit(){
		if(item != null)
			item = itemDao.getItem(item.getId());
		persons = personDao.qryPersons(null);
		hospitals = hospitalDao.qryHospitals(null);
		products = productDao.qryProducts(null);
		return "gotoEdit";
	}
	
	public Item getItem() {
		return item;
	}
	public void setItem(Item item) {
		this.item = item;
	}
	public List<Item> getItems() {
		return items;
	}
	public Pager<Item> getPage() {
		return page;
	}

	public List<Hospital> getHospitals() {
		return hospitals;
	}

	public List<Person> getPersons() {
		return persons;
	}

	public List<Product> getProducts() {
		return products;
	}
	
}
